﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using DA;
using DTO;
using BLL;
namespace Test1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            BaoBLL bao = new BaoBLL();
            DataSet ds = bao.GetAll();
            dataGridView1.DataSource = ds.Tables[0];
            dataGridView1.Refresh();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //SqlConnection con = new SqlConnection(@"Data Source=VIETBN-K53\SQLEXPRESS;Initial Catalog=QLDO;Integrated Security=True");
            //con.Open();

            //DataTable dt = new DataTable();

            //string sql = "SELECT * FROM BAO";
            //SqlDataAdapter sa = new SqlDataAdapter(sql, con);
            //sa.Fill(dt);
            //dataGridView1.DataSource = dt;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            BaoDTO bao = new BaoDTO();
            bao.MaBao = int.Parse(txtMa.Text);
            bao.TenBao = txtTen.Text;

            BaoDA baoda = new BaoDA();
            baoda.Add(bao);
            button1_Click(sender, e);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            BaoDTO bao = new BaoDTO();
            bao.MaBao = int.Parse(txtMa.Text);
            bao.TenBao = txtTen.Text;

            BaoDA baoda = new BaoDA();
            baoda.Update(bao);
            button1_Click(sender, e);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            BaoDTO bao = new BaoDTO();
            bao.MaBao = int.Parse(txtMa.Text);
            bao.TenBao = txtTen.Text;

            BaoDA baoda = new BaoDA();
            baoda.Delete(bao.MaBao);
            button1_Click(sender, e);
        }
    }
}
